﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CROSLAND.BL.BE;
using System.Data.Common;
using System.Configuration;
using System.Data;
using DECOR.BL.BE;

namespace CROSLAND.DL.DALC.MSSQL
{
    public class ParametroDALC : BaseDALC, IParametroDALC 
    {
        
        #region IParametroDALC Members

        public void getDataDDL(ref List<GenericBE> lstAlmacen, ref List<GenericBE> lstAsesores,
            ref List<GenericBE> lstBloEnt, ref List<GenericBE> lstBloFac, ref List<GenericBE> lstCanal,
            ref List<GenericBE> lstCondExp, ref List<GenericBE> lstCondicionPago, ref List<GenericBE> lstGrpCond,
            ref List<GenericBE> lstGrpVend, ref List<GenericBE> lstMotPed, ref List<GenericBE> lstOfVtas,
            ref List<GenericBE> lstOrgVtas, ref List<GenericBE> lstSectores, ref List<GenericBE> lstTipoDoc,
            out DateTime fechaHasta, ref List<GenericBE> lstMotRec, ref List<GenericBE> lstZonaReg,
            ref List<GenericBE> lstGrupoCli, ref List<UbigeoBE> lstUbigeo, ref List<GenericBE> lstCamp, ref List<GenericBE> lstCity,
            ref List<GenericBE> lstColor, ref List<GenericBE> lstDispo, ref List<GenericBE> lstGrpArt, ref List<GenericBE> lstZReg,
            ref List<GenericBE> lstBancoCheque, ref List<GenericBE> lstBancoDepo, ref List<GenericBE> lstProcesadora,
            ref List<LibrosxvstelBE> lstLibrosxvstel, out decimal pIGV)
        {
            string charSep = ParametroDALC.getParamValueStatic("charSep");
            pIGV = 18m; //falta rescatar igv del día de las tablas
            //------------------------------------------------------------------           
            DateTime df = new DateTime();
            df = DateTime.Now;//cambiar
            fechaHasta = df;//cambiar
            lstOfVtas = new List<GenericBE>();
            //lstZipCodes = new List<GenericBE>();
            lstTipoDoc = new List<GenericBE>();
            lstGrpVend = new List<GenericBE>();
            lstSectores = new List<GenericBE>();
            lstMotPed = new List<GenericBE>();
            lstCondExp = new List<GenericBE>();
            lstGrpCond = new List<GenericBE>();
            lstBloEnt = new List<GenericBE>();
            lstBloFac = new List<GenericBE>();
            lstAsesores = new List<GenericBE>();
            lstCamp = new List<GenericBE>();
            lstCondicionPago = new List<GenericBE>();
            lstMotRec = new List<GenericBE>();
            lstUbigeo = new List<UbigeoBE>();
            lstCity = new List<GenericBE>();
            lstColor = new List<GenericBE>();

            lstColor = new List<GenericBE>();
            lstDispo = new List<GenericBE>();
            lstGrpArt = new List<GenericBE>();

            lstBancoCheque = new List<GenericBE>();
            lstBancoDepo = new List<GenericBE>();
            lstProcesadora = new List<GenericBE>();

            GenericBE objBlank = new GenericBE();
            objBlank.Codigo = string.Empty;
            objBlank.Descripcion = string.Empty;

            lstDispo.Add(objBlank);
            lstGrpArt.Add(objBlank);

            GenericBE obj = null;

            DbCommand command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_OFICINAS");
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = obj.Codigo + " :: " + dr["DES_PARAMETRO"].ToString();
                    lstOfVtas.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_FECHA_VALIDEZ");
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    if (!dr["DES_VALOR"].ToString().Equals("") )
                    {
                        fechaHasta = DateTime.Now.AddDays(int.Parse( dr["DES_VALOR"].ToString() ));
                    }

                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_TIPODOC");
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = obj.Codigo + " :: " + dr["DES_PARAMETRO"].ToString();
                    lstTipoDoc.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_SECTORES");
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = obj.Codigo + " :: " + dr["DES_PARAMETRO"].ToString();
                    lstSectores.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_CONDICIONESPAGO");
            lstCondicionPago.Add(objBlank);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = obj.Codigo + " :: "  + dr["DES_PARAMETRO"].ToString();
                    lstCondicionPago.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_CANAL");
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = obj.Codigo + " :: " + dr["DES_PARAMETRO"].ToString();
                    lstCanal.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_ORGVTAS");
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = obj.Codigo + " :: " + dr["DES_PARAMETRO"].ToString();
                    lstOrgVtas.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_ZONA_REGISTRAL");
            lstZReg.Add(objBlank);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstZReg.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_GRUPO_CLIENTE_VEH");
            lstGrupoCli.Add(objBlank);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstGrupoCli.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_TVAGT");
            lstMotRec.Add(objBlank);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstMotRec.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_DISPONIBILIDAD");
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstDispo.Add(obj);                    
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_GRUPO_ARTICULO");
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion =  dr["DES_PARAMETRO"].ToString();
                    lstGrpArt.Add(obj);                    
                }
            }



            //Ubigeos
            command = dbProvider.GetStoredProcCommand("USPR_LEE_UBIGEO");
            UbigeoBE objU = new UbigeoBE();
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    objU = new UbigeoBE();
                    objU.CodigoRegion = dr["ID_REGION"].ToString();
                    objU.DesRegion = dr["DES_REGION"].ToString();
                    objU.CodPoblacion = dr["ID_POBLACION"].ToString();
                    objU.DesPoblacion = dr["DES_POBLACION"].ToString();
                    objU.CodDistrito = dr["ID_DISTRITO"].ToString();
                    objU.DesDistrito = dr["DES_DISTRITO"].ToString();
                    lstUbigeo.Add(objU);
                }
            }


            //Campañas
            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_CAMPANIA");
            lstCamp.Add(objBlank);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstCamp.Add(obj);
                }
            }

            //Poblacion
            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_CIUDAD");
            lstCity.Add(objBlank);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstCity.Add(obj);
                }
            }
            //Color
            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_COLOR");
            lstColor.Add(objBlank);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstColor.Add(obj);
                }
            }

            //Lista Banco Cheque
            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_BCOCHEQUE");
            //lstBancoCheque.Add(objBlank);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstBancoCheque.Add(obj);
                }
            }

            //Lista Banco Deposito
            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_BCODEPOSITO");
            //lstColor.Add(objBlank);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstBancoDepo.Add(obj);
                }
            }

            //Lista Tipo Procesadora
            command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "T_TIPOPRO");
            //lstColor.Add(objBlank);
            GenericBE blanco = new GenericBE();
            blanco.Codigo = " ";
            blanco.Descripcion = "Seleccionar Operador";
            lstProcesadora.Add(blanco);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString();
                    obj.Descripcion = dr["DES_PARAMETRO"].ToString();
                    lstProcesadora.Add(obj);
                }
            }

            //Libros por puestos de exp.
            command = dbProvider.GetStoredProcCommand("USPR_LEE_LIBROSXPUESTOS");
            LibrosxvstelBE objL = new LibrosxvstelBE();
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    objL = new LibrosxvstelBE();
                    objL.Bukrs = dr["BUKRS"].ToString();
                    objL.Vstel = dr["VSTEL"].ToString();
                    objL.Invtp = dr["INVTP"].ToString();
                    objL.Rgtno = dr["RGTNO"].ToString();
                    objL.Auart = dr["AUART"].ToString();
                    objL.Flag = dr["FLAG"].ToString();
                    objL.NroSerie = dr["NROSERIE"].ToString();
                    objL.DocSecuencia = dr["DOCSECUENCIA"].ToString();
                    lstLibrosxvstel.Add(objL);
                }
            }
        }

        public void get_Param_PFact(ref List<GenericBE> lstDenom, ref List<GenericBE> lstMoneda,
            ref List<GenericBE> lstMotivoBloq, ref List<GenericBE> lstClaseDoc,
            ref List<GenericBE> lstRFACT, ref List<GenericBE> lstSTATU,
            ref List<GenericBE> lstTFPLU, ref List<GenericBE> lstCPag)
        {
            string charSep = ParametroDALC.getParamValueStatic("charSep");

            lstDenom = new List<GenericBE>();
            lstMoneda = new List<GenericBE>();
            lstMotivoBloq = new List<GenericBE>();
            lstClaseDoc = new List<GenericBE>();
            lstRFACT = new List<GenericBE>();
            lstSTATU = new List<GenericBE>();
            lstTFPLU = new List<GenericBE>();
            lstCPag = new List<GenericBE>();

            GenericBE blanco = new GenericBE();
            blanco.Codigo = " ";
            blanco.Descripcion = " ";

            GenericBE obj = null;
            DbCommand command = dbProvider.GetStoredProcCommand("ZWEV_T_RFACT");
            lstRFACT.Add(blanco);

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DOMVALUE_L"].ToString();
                    obj.Descripcion = dr["DOMVALUE_L"].ToString() + charSep + dr["DDTEXT"].ToString();
                    lstRFACT.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("ZWEV_T_STATU");
            lstSTATU.Add(blanco);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["DOMVALUE_L"].ToString();
                    obj.Descripcion = dr["DOMVALUE_L"].ToString() + charSep + dr["DDTEXT"].ToString();
                    lstSTATU.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("ZWEV_T_TCURT");
            lstMoneda.Add(blanco);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["WAERS"].ToString();
                    obj.Descripcion = dr["WAERS"].ToString() + charSep + dr["LTEXT"].ToString();
                    lstMoneda.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("ZWEV_T_TFPLU");
            lstTFPLU.Add(blanco);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["FPTTP"].ToString();
                    obj.Descripcion = dr["FPTTP"].ToString() + charSep + dr["TTBEZ"].ToString();
                    lstTFPLU.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("ZWEV_T_TVFKT");
            lstClaseDoc.Add(blanco);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["FKART"].ToString();
                    obj.Descripcion = dr["FKART"].ToString() + charSep + dr["VTEXT"].ToString();
                    lstClaseDoc.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("ZWEV_T_TVFST");
            lstMotivoBloq.Add(blanco);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["FAKSP"].ToString();
                    obj.Descripcion = dr["FAKSP"].ToString() + charSep + dr["VTEXT"].ToString();
                    lstMotivoBloq.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("ZWEV_T_TVTBT");
            lstDenom.Add(blanco);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    if (dr["TETBE"].ToString() == "Z001" || dr["TETBE"].ToString() == "Z002")
                    {
                        obj = new GenericBE();
                        obj.Codigo = dr["TETBE"].ToString();
                        obj.Descripcion = dr["TETBE"].ToString() + charSep + dr["TEBEZ"].ToString();
                        lstDenom.Add(obj);
                    }
                }
            }

            command = dbProvider.GetStoredProcCommand("ZWEV_T_CPAG");
            lstCPag.Add(blanco);
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    obj = new GenericBE();
                    obj.Codigo = dr["ZTERM"].ToString();
                    obj.Descripcion = dr["ZTERM"].ToString() + charSep + dr["TEXT1"].ToString();
                    lstCPag.Add(obj);
                }
            }

        }

        public int getDecimales()
        {
            return ParametroDALC.getDecimalesStatic;
        }

        public decimal getIGV()
        {
            throw new NotImplementedException();
        }

        public decimal getTipoCambio()
        {
            decimal ex_tipoCambio = 0;
            //string pFecha = dateNetToSap(DateTime.Now);
            DbCommand command = dbProvider.GetStoredProcCommand("USPR_TIPO_CAMBIO");

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                if (dr.Read())
                {
                    ex_tipoCambio = Convert.ToDecimal(dr["DES_PARAMETRO"].ToString());
                }
            }

            return ex_tipoCambio;     
        }

        public decimal getTipoCambio(DateTime pFecha)
        {
            decimal ex_tipoCambio = 0;
            //string pFecha = dateNetToSap(DateTime.Now);
            DbCommand command = dbProvider.GetStoredProcCommand("USPR_TIPO_CAMBIO");

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                if (dr.Read())
                {
                    ex_tipoCambio = Convert.ToDecimal(dr["DES_PARAMETRO"].ToString());
                }
            }

            return ex_tipoCambio;  
        }

        public List<GenericBE> getListaZipCode()
        {
            throw new NotImplementedException();
        }

        public ClienteBE getClienteReniec(string pDNI)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// Busca en el archivo de configuración el valor de un key
        /// </summary>
        /// <param name="key">Nombre de una entrada en el archivo de configuración</param>
        /// <returns>Valor asociado al key</returns>
        public string getParamValue(string key)
        {
            return getParamValueStatic(key);
        }

        public bool esTipoXY(string pCodigo, string pConfigKey)
        {
            return esTipoX(pCodigo, pConfigKey);
        }

        #endregion

        public static DateTime dateSapToNet(string pFechaSAP)
        {
            DateTime tmpVar = new DateTime();
            try
            {
                tmpVar = new DateTime(Convert.ToInt16(pFechaSAP.Substring(0, 4)), Convert.ToInt16(pFechaSAP.Substring(4, 2)), Convert.ToInt16(pFechaSAP.Substring(6, 2)));
            }
            catch { tmpVar = new DateTime(); }
            return tmpVar;
        }

        public static string dateNetToSap(DateTime pFechaNET)
        {
            try
            {
                return pFechaNET.Year.ToString().PadLeft(4, '0') + pFechaNET.Month.ToString().PadLeft(2, '0') + pFechaNET.Day.ToString().PadLeft(2, '0');
            }
            catch { return string.Empty; }
        }

        public static string getParamValueStatic(string key)
        {
            return ConfigurationManager.AppSettings[key];
        }


        /// <summary>
        /// Verifica que sea un tipo determinado.
        /// </summary>
        /// <param name="pCodigo">Valor que se pide verificar.</param>
        /// <param name="pConfigKey">Llave que es buscada en el archivo de configuración.</param>
        /// <returns>Devuelve true o false </returns> 
        public static bool esTipoX(string pCod, string pConfigKey)
        {
            try
            {
                string[] codTipoDoc = getParamValueStatic(pConfigKey).Split(',');
                foreach (string str in codTipoDoc)
                {
                    if (pCod == str)
                    {
                        return true;
                    }
                }
                return false;
            }
            catch 
            {
                return false;
            }
            
        }

        public static int getDecimalesStatic
        {
            get { return Convert.ToInt16(getParamValueStatic("Decimales")); }
        }

        public List<GenericBE> cmbCampana(List<string> lstLote)
        {
            throw new NotImplementedException();
        }

        public List<GenericBE> obtenerTipoDocFactura(string idTabla)
        {
            List<GenericBE> entitys = new List<GenericBE>();
            DbCommand command = dbProvider.GetStoredProcCommand("USPR_OBTENER_PARAMETRO");

            dbProvider.AddInParameter(command, "ID_TABLA", DbType.String, idTabla);

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    GenericBE entity = new GenericBE();

                    entity.Codigo = dr["DES_VALOR"].ToString();
                    entity.Descripcion = dr["DES_PARAMETRO"].ToString();

                    entitys.Add(entity);
                }
            }

            return entitys;   
        }

        #region IParametroDALC Members

        /// <summary>
        /// Recupera una lista de tipo de documentos
        /// </summary>
        /// <returns></returns>        
        public List<GenericBE> getDocVtaCot()
        {
            List<GenericBE> entitys = new List<GenericBE>();
            DbCommand command = dbProvider.GetStoredProcCommand("ZCM_SD_009");

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    GenericBE entity = new GenericBE();
                  
                    entity.Codigo = dr["ID"].ToString();
                    entity.Descripcion = dr["CLVTA"].ToString();                   

                    entitys.Add(entity);
                }
            }

            return entitys;      
        }

        #endregion

        public List<GenericBE> cmbTipodocFac()
        {
            List<GenericBE> entitys = new List<GenericBE>();
            DbCommand command = dbProvider.GetStoredProcCommand("USPR_LEE_PARAMETRO");
            dbProvider.AddInParameter(command, "NOMBRE_TABLA", DbType.String, "TIPO_DOC_FAC");
            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    GenericBE obj = new GenericBE();
                    obj.Codigo = dr["DES_VALOR"].ToString() + "-" + dr["ADIC1"].ToString();
                    obj.Descripcion =  dr["DES_PARAMETRO"].ToString();
                    obj.Adic1 = dr["ADIC1"].ToString();
                    entitys.Add(obj);
                }
            }

            return entitys;
            
        }


        #region Miembros de IParametroDALC


        public decimal getImpuesto(string claseCondicion, string clasif_cliente, string clasif_material)
        {
            decimal impuesto = 0;
            DbCommand command = dbProvider.GetStoredProcCommand("USPR_LEE_IMPUESTO");
            dbProvider.AddInParameter(command, "CLASE_CONDICION", DbType.String, claseCondicion);
            dbProvider.AddInParameter(command, "CLASIF_FISCAL_CLIENTE", DbType.String, clasif_cliente);
            dbProvider.AddInParameter(command, "CLASIF_FISCAL_MATERIAL", DbType.String, clasif_material);

            return impuesto = Convert.ToDecimal(dbProvider.ExecuteScalar(command));
        }

        #endregion

        public void getFolioClaseDocumentoPedFac(string numDoc, out string folio, out string claseDocumento, out string tipo)
        {
            DbCommand command = dbProvider.GetStoredProcCommand("USPR_LEE_FOLIO");
            dbProvider.AddInParameter(command, "NROPEDIDO", DbType.String, numDoc);

            string _folio = "", _clasedoc = "", _tipo = "";

            DataTable dt = new DataTable("datos");
            dt.Load(dbProvider.ExecuteReader(command));
            if (dt.Rows.Count > 0)
            {
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
                _folio = ds.Tables["datos"].Rows[0]["FOLIO"].ToString();
                _clasedoc = ds.Tables["datos"].Rows[0]["AUART"].ToString();
                _tipo = ds.Tables["datos"].Rows[0]["TIPO"].ToString();    
            }
            
            folio = _folio;
            claseDocumento = _clasedoc;
            tipo = _tipo;
        }


        public void getDatosUbicación(out  List<GenericBE> lstReg, out List<PoblacionBE> lstPob)
        {

            lstReg = new List<GenericBE>();
            lstPob = new List<PoblacionBE>();
            DbCommand command = dbProvider.GetStoredProcCommand("USPR_REG_POB");
            dbProvider.AddInParameter(command, "@TIPO", DbType.String, 1);//TRAIGO REGIONES

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    GenericBE obj = new GenericBE();
                    obj.Codigo = dr["CODIGO"].ToString().Trim();
                    obj.Descripcion = dr["Descripcion"].ToString().Trim();
                    lstReg.Add(obj);
                }
            }

            command = dbProvider.GetStoredProcCommand("USPR_REG_POB");
            dbProvider.AddInParameter(command, "@TIPO", DbType.String, 2);//TRAIGO REGIONES

            using (IDataReader dr = dbProvider.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    PoblacionBE obj = new PoblacionBE();
                    obj.Codigo = dr["Codigo"].ToString().Trim();
                    obj.Descripcion = dr["Descripcion"].ToString().Trim();
                    obj.Region = dr["Region"].ToString().Trim();
                    lstPob.Add(obj);
                }
            }
        }
    }
}
